package com.wd.jetpack.base

import android.content.Context
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import com.wd.jetpack.BR

/**
 * NA<BR>
 *
 * @author w4425
 * @version [V5.9.3, 2021/6/4]
 * @since V5.9.3
 */
abstract class BaseActivity<VB : ViewDataBinding> : AppCompatActivity(), Presenter {
    //声明binding
    protected val mBinding: VB by lazy {
        DataBindingUtil.inflate<VB>(layoutInflater, getLayoutId(), null, false)
    }
    protected val mContext: Context by lazy { this }
    abstract fun getLayoutId(): Int
    abstract fun initView()
    abstract fun initData()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(mBinding.root)
        //绑定点击事件
        mBinding.setVariable(BR.presenter, this)
        mBinding.executePendingBindings()
        //绑定生命周期
        mBinding.lifecycleOwner = this
        initView()
        initData()
    }
}